Developer Documentation

QuickTime 4 API Documentation

Inside Macintosh: Sound

| Previous | Chapter contents | Chapter top | Section top | Next |

Recording a Sound File

To record a sound directly into a file, you can call the SndRecordToFile function, which works exactly like SndRecord except that you pass it the file reference number of an open file instead of a handle to some memory. When SndRecordToFile exits successfully, that file contains the recorded audio data in AIFF or AIFF-C format. You can then play the recorded sound by passing that file reference number to the SndStartFilePlay function. (See Listing 0-2 for a sample function that uses the SndStartFilePlay function.) Listing 0-6 defines a procedure that records a sound into a file using SndRecordToFile .

Listing 6 Recording a sound file

PROCEDURE MyRecordSoundFile (myFileRefNum: Integer);
VAR
    myErr:          OSErr;
    myCorner:       Point;
BEGIN
    MyGetTopLeftCorner(myCorner);
    myErr := SndRecordToFile(NIL, myCorner, siBestQuality, myFileRefNum);
    IF (myErr <> noErr) AND (myErr <> userCanceledErr) THEN
        DoError(myErr);
END;

The SndRecordToFile function records the sound in the file specified in its fourth parameter. You must open the file before calling the MyRecordSoundFile procedure, and you must close the file after calling it. For more information on creating, opening, and closing files, see the chapter "Introduction to File Management" in Inside Macintosh: Files .


© 1999 Apple Computer, Inc.

| Previous | Chapter contents | Chapter top | Section top | Next |